package com.roc.web.action.merinfo;

import java.util.ArrayList;
import java.util.List;

import com.roc.page.BaseSearchCondition;
import com.roc.page.WhereHQLFieldBean;
import com.roc.util.Constance;
import com.roc.util.constant.Role;

public class MerAreaSearchCondtion extends BaseSearchCondition {
	private String merNo; //商户号
	private String merName; //商户简称
	private String provNo; //32域
	private String roleType;
	
	@Override
	protected List<WhereHQLFieldBean> getWhereHQLFieldBeanList() {
		List<WhereHQLFieldBean> filedBeanList = new ArrayList<WhereHQLFieldBean>();
		if(Constance.isNotEmpty(merNo)){
			filedBeanList.add(new WhereHQLFieldBean("t.mcht_cd", merNo.trim(), "=" , false));
		}
		if(Constance.isNotEmpty(merName)){
			filedBeanList.add(new WhereHQLFieldBean("t.name_busi", merName.trim(), "=", false));
		}
		return filedBeanList;
	}

	@Override
	protected String getRowCountHQL() {
		StringBuffer sb = new StringBuffer();
		sb.append("select count(1) from tbl_mcht_inf t left join tbl_mcht_bankaccount b on t.mcht_cd = b.owner_cd ");
		if(!Role.SYSTEM.getCode().equals(roleType)){
			sb.append("where t.bank_belong_cd = '48502000' and t.uc_bc_cd_32 in ");
			sb.append("(select '4850' || area_no from apstfr.tbl_area_unionpay_inf where prov_no = ").append(provNo).append(")");
		}
		return sb.toString();
	}

	@Override
	protected String getSearchHQL() {
		StringBuffer sb = new StringBuffer();
		sb.append("SELECT t.mcht_cd, t.name_busi, t.name tname,(select t1.ins_name FROM tbl_ins_inf t1 where t1.ins_id_cd='48502000') insName,");
		sb.append("t.contact_name,t.contact_phoneno,t.certif,t.certif_no,t.busi_lice_no,t.reg_addr,t.status,");
		sb.append("t.uc_bc_cd_32,(SELECT o1.real_name FROM t_Operators o1 where o1.id = t.ext1) realName,");
		sb.append("(select a.name from tbl_area a where a.id = (SELECT o2.companyid FROM t_operators o2 where o2.id = t.ext1)) companyName,");
		sb.append("b.name bname,b.account,b.bank_name,b.bank_code,t.group_cd,t.nation_cd,");
		sb.append("(nvl2((select distinct d1.prod_cd FROM tbl_mcht_biz_deal d1 where d1.mcht_cd = t.mcht_cd and d1.prod_cd='1000'),'T1','')),");
		sb.append("(nvl2((select distinct d2.prod_cd FROM tbl_mcht_biz_deal d2 where d2.mcht_cd = t.mcht_cd and d2.prod_cd='1171'),'T0','')),");
		sb.append("(nvl2((select distinct d3.prod_cd FROM tbl_mcht_biz_deal d3 where d3.mcht_cd = t.mcht_cd and d3.prod_cd='3000'),'直连T1','')),");
		sb.append("(nvl2((select distinct d4.prod_cd FROM tbl_mcht_biz_deal d4 where d4.mcht_cd = t.mcht_cd and d4.prod_cd='1271'),'直连T0','')) ");
		sb.append(" from tbl_mcht_inf t left join tbl_mcht_bankaccount b on t.mcht_cd = b.owner_cd ");
		if(!Role.SYSTEM.getCode().equals(roleType)){
			sb.append(" where t.bank_belong_cd = '48502000' and t.uc_bc_cd_32 in ");
			sb.append("(select '4850' || au.area_no from apstfr.tbl_area_unionpay_inf au where au.prov_no = ").append(provNo).append(")");
		}
		return sb.toString();
	}

	@Override
	protected String getOrderPartOfHQL() {
		return " order by t.rec_crt_ts desc ";
	}

	public String getMerNo() {
		return merNo;
	}

	public void setMerNo(String merNo) {
		this.merNo = merNo;
	}

	public String getMerName() {
		return merName;
	}

	public void setMerName(String merName) {
		this.merName = merName;
	}

	public String getProvNo() {
		return provNo;
	}

	public void setProvNo(String provNo) {
		this.provNo = provNo;
	}

	public String getRoleType() {
		return roleType;
	}

	public void setRoleType(String roleType) {
		this.roleType = roleType;
	}

}